package lagou.homework.lagouhomework.Unit3.code.q3;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;
public class TestHashMap {
    public static void countStr(String s1){
        String[] arr1 =s1.split(",");
        Map<String,Integer> strMap = new HashMap<>();
        for (int i =0;i<arr1.length;i++) {
            if (strMap.containsKey(arr1[i])) {
                strMap.put(arr1[i], strMap.get(arr1[i])+1);

            }else{
                strMap.put(arr1[i], 1);
            }
        }
        // 打印结果
        Set<String> strs = strMap.keySet();
        for (String str : strs) {
            System.out.println(str + "出现了"+strMap.get(str)+ "次;");
        }
    }

    public static void main(String[] args) {
        String s1= "123,456,789,123,456";
        countStr(s1);

    }

}
